package com.yonyou.gmmc.service.wechatpush.event.controller;

import java.util.HashMap;
import java.util.Map;

import org.marketing.common.dto.MQReceiveResult;
import org.marketing.common.event.BizEvent;
import org.marketing.common.event.EventRegisterSigninDTO;
import org.marketing.common.event.MessageEvent;
import org.marketing.common.event.enums.EventConstant.EventBizStep;
import org.marketing.common.event.enums.EventConstant.EventBizType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.gmmc.service.wechatpush.common.ApiVersionConsts;
import com.yonyou.gmmc.service.wechatpush.event.handler.HandleResult;
import com.yonyou.gmmc.service.wechatpush.event.service.WechatEventService;
import com.netflix.discovery.converters.Auto;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = ApiVersionConsts.BASE_PATH + ApiVersionConsts.VERSION)
@Api("微信推送相关API")
public class WechatEventController {
	
	@Autowired
	private WechatEventService wechatEventService;

	/**
	 * 接收关键事件，判断是否要推送微信消息
	 * 
	 * @return
	 */
	@RequestMapping(value="/event",method = RequestMethod.POST)
	@ApiOperation(value="接收MQ传来的关键事件",notes="接收事件进行微信消息推送")
	public MQReceiveResult receiveEvent(@RequestBody BizEvent event){
		//代码扫描  1480
		BizEvent bizEvent = new BizEvent();
		bizEvent.setEventBizStep(event.getEventBizStep());
		bizEvent.setEventBizType(event.getEventBizType());
		bizEvent.setEventKey(event.getEventKey());
		bizEvent.setEventData(event.getEventData());
		HandleResult handleResult = wechatEventService.HandleWechatEvent(bizEvent);
		
		MQReceiveResult result = new MQReceiveResult();
		result.setMessage(handleResult.getMessage());
		result.setResult("200");
		return result;
	}
}
